package com.lysj.merchant.app.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.crypto.digest.BCrypt;
import com.lysj.admin.utils.annotation.UserId;
import com.lysj.admin.utils.constant.CommonConstant;
import com.lysj.admin.utils.exception.BaseException;
import com.lysj.admin.utils.spring.foundation.base.BaseContent;
import com.lysj.admin.utils.validation.Validation;
import com.lysj.admin.utils.validation.domain.BindingResult;
import com.lysj.admin.utils.web.ParamUtil;
import com.lysj.admin.utils.web.Resp;
import com.lysj.merchant.desk.domain.Desk;
import com.lysj.merchant.desk.dto.DeskQueryDto;
import com.lysj.merchant.desk.service.DeskRoomService;
import com.lysj.merchant.desk.service.DeskService;
import com.lysj.merchant.management.domain.User;
import com.lysj.merchant.management.service.ManagementService;
import com.lysj.merchant.management.service.UserService;
import com.lysj.merchant.merchant.service.StoreService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Created by wtl on 2019-03-28 17:27
 * @description 商户app
 */
@RestController
@RequestMapping("/merchant/management/app")
public class AppManagementController extends BaseContent {


    @Resource
    private ManagementService managementService;

    @Resource
    private StoreService storeService;

    @Resource
    private UserService userService;


    /**
     * @author Created by wtl on 2019/3/28 17:48
     * @Description 商户获取验证码
     */
    @GetMapping("/get_captcha")
    public Resp getCaptcha(String phone) {
        return new Resp().success(managementService.getCaptcha(phone));
    }

    /**
     * @author Created by wtl on 2019/3/28 17:29
     * @Description 商户忘记密码
     */
    @PostMapping("/forget_password")
    public Resp forgetPassword(String phone, String captcha, String password) {
        return new Resp().success(managementService.forgetPassword(phone, captcha, password));
    }

    /**
     * @author Created by wtl on 2019/4/12 14:54
     * @Description 获取门店信息
     */
    @GetMapping("/find_store_info")
    public Resp findStoreInfo(String storeId) {
        if (ParamUtil.isBlank(storeId)) {
            return new Resp().error(Resp.Status.PARAM_ERROR, "门店id为空");
        }
        return new Resp().success(storeService.findOne(storeId));
    }

    /**
     * @author Created by wtl on 2019/4/12 15:04
     * @Description 商户修改密码
     */
    @PostMapping("/modify_password")
    public Resp modifyPassword(@UserId String userId, String password, String newPassword) {
        return new Resp().success(userService.modifyPassword(userId, password, newPassword));
    }

    /**
     * @author Created by wtl on 2019/4/12 15:10
     * @Description 退菜
     */




    /*
     * @author drj
     * @date 2019-04-09 17:43
     * @Description :获取餐桌列表
     */
    @GetMapping("/desk/list")
    public Resp deskList(DeskQueryDto desk) {
        return new Resp().success(managementService.deskService.findDeskList(desk));
    }

    /*
     * @author drj
     * @date 2019-04-10 15:42
     * @Description :修改餐桌
     */
    @PostMapping("/desk/update")
    public Resp deskUpdate(Desk model) {
        Desk desk = managementService.deskService.findOne(model.getId());
        CopyOptions copyOptions = CopyOptions.create();
        copyOptions.setIgnoreNullValue(true);
        BeanUtil.copyProperties(model, desk, copyOptions);
        managementService.deskService.save(desk);
        return (new Resp()).success("操作成功");
    }

    /*
     * @author drj
     * @date 2019-04-10 16:08
     * @Description :获取门店餐桌空间列表
     */
    @GetMapping("/store/desk_room/select_item")
    public Resp deskRoomSelectItem(String storeId) {
        return new Resp().success(managementService.deskRoomService.getRepository().selectItems(storeId));
    }

    /**
     * @author Created by wtl on 2019/4/11 16:05
     * @Description 结账生成支付码
     */


}
